package com.example.annolog.interceptor;

import com.example.annolog.anno.Log;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class LogAnnoAspect {

    @Pointcut("@annotation(loganno)")
    public void beforeTest(JoinPoint point, Log loganno) {//todo 何时调用
        System.out.println("method " + point.getSignature().getName() + " is called on " + point.getThis() + " with " +
                "args" +
                " " + point.getArgs());
        System.out.println("before invoke: " + loganno.toString());
    }

    @AfterReturning(value = "beforeTest(point,loganno)", returning = "rvt")
    public void afterTest(JoinPoint point, Log loganno, Object rvt) {
        System.out.println("method " + point.getSignature().getName() + " returns " + rvt);
        System.out.println("after invoke: " +loganno.toString());
    }
}

